$(function() {


	localStorage.indexName = titleIndex;
	$.ajax({
		url: 'http://47.89.20.150/czlycms/index.php?m=Web&a=aboutUs',
		type: 'GET',
		dataType: 'JSONP'
	})
	.done(function(data) {
		console.log("success");
		console.log(data);
		overviewFun(data.overview);
		factsFun(data.facts);
		businessFun(data.business);
		corporateFun(data.corporate);

	})
	.fail(function() {
		console.log("error");
	})
	.always(function() {
		console.log("complete");
	});







// overview
function overviewFun(data){
	var overviewCon = $('#overviewCon');
	var html = '';
	var ind  = true; 
	for (var i = 0; i < data.length; i++) {

		var cn = '<li class="'+indTH()+'">'+
		'<div class="lin"><span></span></div>'+
		'<h4>'+data[i].title+'</h4>'+
		'<p>'+data[i].description+'</p>'+
		'<img src="'+data[i].image_url+'">'+
		'</li>';
		html+=cn;

	}
	overviewCon.html(html);

	function indTH(){
		if (ind) {
			ind = false;
			return  'T';
		}else{
			ind = true;
			return  'B';
		}
	}
}

// overview end





// facts
function factsFun(data){
	var FactsCon = $('#FactsCon');
	var html = '';

	var icon = ['&#xe637;','&#xe638;','&#xe647;','&#xe63a;']
	for (var i = 0; i < data.length; i++) {

		var cn = '<li>'+
		'<div class="iconC"><i class="iconfont">'+icon[i]+'</i></div>'+
		'<div class="ind" id="ind-'+(i+1)+'">'+data[i].value+ifType(data[i].type)+'</div>'+
		'<p>'+data[i].title+'</p></li>';
		html+=cn;

	}
	FactsCon.html(html);

	FactsFunXun(data)

	function ifType(type){
		if (type == "percent") {
			return '%';
		}else{
			return ' ';
		}
	}


}

// facts end







	 //Key Facts 数据 缓冲效果
	 function FactsFunXun(data){
	 	console.log(data);
	 	if ($('section.Facts').length>0) {

	 		var options = {
	 			 useEasing : true,
	 			  useGrouping : true,
	 			  separator : '',
	 			  decimal : '.',
	 			  prefix : '',
	 			  suffix : ''

	 		};

	 		$('section.Facts').waypoint(function(){
	 			var numAnim = new CountUp("ind-1", 0,  intedata(data[0].value,data[0].type), IfTyle(data[0].type), 3.5, options);
	 			numAnim.start();
	 			var numAnim = new CountUp("ind-2", 0,  intedata(data[1].value,data[1].type), IfTyle(data[1].type), 3.5, options);
	 			numAnim.start();
	 			var numAnim = new CountUp("ind-3", 0,  intedata(data[2].value,data[2].type), IfTyle(data[2].type), 3.5, options);
	 			numAnim.start();
	 			var numAnim = new CountUp("ind-4", 0,  intedata(data[3].value,data[3].type), IfTyle(data[3].type), 3.5, options);
	 			numAnim.start();

	 		}, { offset: '100%' });
	 	};



	 	function IfTyle(type){
	 		if (type== "fload") {
	 			return 2;
	 		}else{
	 			return 0;
	 		}
	 	}

	 	function intedata(int,type){
	 		if (type == "fload") {
	 			return parseFloat(int)
	 		}else{
	 			return parseInt(int);
	 		}
	 	}
	 }



 //Key Facts 数据 缓冲效果 end




// corporate

function corporateFun(data){
	var ManagementList = $('#ManagementList');
	var html = '';

	for (var i = 0; i < data.length; i++) {

		var cn = '<li><a href="'+data[i].url+'"><div class="title">'+data[i].title+'</div><div class="imgC"><img src="'+data[i].image_url+'"></div></a></li>';
		html+=cn;

	}
	ManagementList.html(html);
}

// corporate end


// business
function businessFun(data){
	var BusinessMapNa =$('#BusinessMapNa');
	var Maplist = BusinessMapNa.find('li');
	MapData = data;
	console.log(MapData);

	for(var i in MapData){
		Mapdefault.push(i);
		
	}
	
	// for (var j = 0; j < Mapdefault.length; j++) {
	// 	Maplist.eq(j).attr('data-name',Mapdefault[j])
	// }

	BusinessMapFun(Mapdefault[0]);

	Maplist.hover(function(){
		var val = $(this).attr('data-name');

		mapIconInd = $(this).index()+1;
		$(this).addClass('active').siblings().removeClass('active');

		if (val =='PARTNERSHIPS') {
			$('#BusinessMap').hide();
			$('#partnershipsImg').show();
		}else{
			$('#BusinessMap').show();
			$('#partnershipsImg').hide();
			SetMapFun(val);
		}

	},function(){

	})


}
// business end




})




